﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using TVDL4.VO;
using TVDL4.BUS;
using C1.Win.C1FlexGrid;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;

namespace TVDL4
{
    public partial class frmGiaiDoan : frmParent
    {
        private const string XML_FILE_PHUTRACH = "PhuTrachObject.xml";
        private const string XML_FILE_GIAIDOAN = "GiaiDoanObject.xml";
        private const string XML_FILE_THINGHIEMCHINH = "ThiNghiemChinhObject.xml";
        private const string XML_FILE_HIEUQUA = "HieuQuaObject.xml";
       
        public GiaiDoanVO GiaiDoanVO;
        private GiaiDoanBUS GiaiDoanBUS;
        private Module.ClickButtonStatus flagButton = Module.ClickButtonStatus.Ngung;//co phan biet dang o trang thai ghi hay ngung
        public frmGiaiDoan()
        {
            InitializeComponent();
            GiaiDoanBUS = new GiaiDoanBUS();
        }

        private void frmGiaiDoan_Load(object sender, EventArgs e)
        {
            //lstGiaiDoanVO = GiaiDoanBUS.GetListGiaiDoan();
            FormatFlexMauDat();
            FormatFlexCongDat();
            FormatFlexMauDa();
            FormatFlexMauCat();
            FormatFlexMauNuoc();
            FormatFlexThachHoc();
            FormatFlexThuyVan();
            GetPhuTrach();
            GetCongTrinh();
            GetGiaiDoan();
            LoadVatlieuToCombo();
            FormatFlexNguoiThucHien();
            
        }
        #region "Private Method"
        private void FormatFlexNguoiThucHien()
        {
            
            // Load the customer object from the existing XML file (if any)...
            PhuTrach phutrach = ObjectXMLSerializer<PhuTrach>.Load(XML_FILE_PHUTRACH);
            ThiNghiemChinh thinghiemchinh = ObjectXMLSerializer<ThiNghiemChinh>.Load(XML_FILE_THINGHIEMCHINH);
            HieuQua hieuqua = ObjectXMLSerializer<HieuQua>.Load(XML_FILE_HIEUQUA);
            phutrach.Names.Sort();
            foreach (string Item in phutrach.Names)
            {
                flexNguoiThucHien.Cols["NguoiThucHien"].ComboList = flexNguoiThucHien.Cols["NguoiThucHien"].ComboList 
                    + "|" + Item;
            }
            foreach (string Item in thinghiemchinh.Names)
            {
                flexNguoiThucHien.Cols["ThiNghiemChinh"].ComboList = flexNguoiThucHien.Cols["ThiNghiemChinh"].ComboList
                    + "|" + Item;
            }
            foreach (string Item in hieuqua.Names)
            {
                flexNguoiThucHien.Cols["HieuQua"].ComboList = flexNguoiThucHien.Cols["HieuQua"].ComboList
                    + "|" + Item;
            }
        
        }
        private void FormatFlexMauDat()
        {
            flexMauDat.Rows[0].AllowMerging = true;
            flexMauDat.Cols[0].AllowMerging = true;
            flexMauDat.Rows[0].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauDat.Rows[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauDat.Cols[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauDat.Rows[1].HeightDisplay = 40;
            flexMauDat.Rows[2].Height = 20;

            flexMauDat.Rows[0][0] = "Mẫu\r\nđất";
            flexMauDat.Rows[1][0] = "Mẫu\r\nđất";
            //Mẫu Thực
            flexMauDat.Rows[1][1] = "Đất nguyên \r\ndạng";
            flexMauDat.Rows[1][2] = "Đất rời";
            flexMauDat.Rows[1][3] = "Đất vật \r\nliệu";
            flexMauDat.Rows[1][4] = "Mẫu độ \r\nẩm";
            flexMauDat.Rows[1][5] = "Mẫu đầm \r\nchặt";

            //Mẫu Bốc
            flexMauDat.Rows[1][6] = "Đất nguyên \r\ndạng";
            flexMauDat.Rows[1][7] = "Đất rời";
            flexMauDat.Rows[1][8] = "Đất vật \r\nliệu";
            flexMauDat.Rows[1][9] = "Mẫu độ \r\nẩm";
            flexMauDat.Rows[1][10] = "Mẫu đầm \r\nchặt";

            //Tổng mẫu thực hiện
            flexMauDat.Rows[1][11] = "Đất nguyên \r\ndạng";
            flexMauDat.Rows[1][12] = "Đất rời";
            flexMauDat.Rows[1][13] = "Đất vật \r\nliệu";
            flexMauDat.Rows[1][14] = "Mẫu độ \r\nẩm";
            flexMauDat.Rows[1][15] = "Mẫu đầm \r\nchặt";

            //Tổng số mẫu không xuất bản
            flexMauDat.Rows[1][16] = "Đất nguyên \r\ndạng";
            flexMauDat.Rows[1][17] = "Đất rời";
            flexMauDat.Rows[1][18] = "Đất vật \r\nliệu";
            flexMauDat.Rows[1][19] = "Mẫu độ \r\nẩm";
            flexMauDat.Rows[1][20] = "Mẫu đầm \r\nchặt";

            //Tổng số mẫu xuất bản
            flexMauDat.Rows[1][21] = "Đất nguyên \r\ndạng";
            flexMauDat.Rows[1][22] = "Đất rời";
            flexMauDat.Rows[1][23] = "Đất vật \r\nliệu";
            flexMauDat.Rows[1][24] = "Mẫu độ \r\nẩm";
            flexMauDat.Rows[1][25] = "Mẫu đầm \r\nchặt";
        }
        private void FormatFlexMauDa()
        {
            flexMauDa.Rows[0].AllowMerging = true;
            flexMauDa.Cols[0].AllowMerging = true;
            flexMauDa.Rows[0].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauDa.Rows[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauDa.Cols[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauDa.Rows[1].HeightDisplay = 40;
            flexMauDa.Rows[2].Height = 20;

            flexMauDa.Rows[0][0] = "Mẫu\r\nđá";
            flexMauDa.Rows[1][0] = "Mẫu\r\nđá";
            //Mẫu Thực

            flexMauDa.Rows[1][1] = "Mẫu đá \r\ncơ lý";
            flexMauDa.Rows[1][2] = "Mẫu đá \r\nvật liệu";
            //Mẫu Bốc
            flexMauDa.Rows[1][3] = "Mẫu đá \r\ncơ lý";
            flexMauDa.Rows[1][4] = "Mẫu đá \r\nvật liệu";         
            //Tổng mẫu thực hiện
            flexMauDa.Rows[1][5] = "Mẫu đá \r\ncơ lý";
            flexMauDa.Rows[1][6] = "Mẫu đá \r\nvật liệu"; 
            //Tổng số mẫu không xuất bản
            flexMauDa.Rows[1][7] = "Mẫu đá \r\ncơ lý";
            flexMauDa.Rows[1][8] = "Mẫu đá \r\nvật liệu";
            //Tổng số mẫu xuất bản
            flexMauDa.Rows[1][9] = "Mẫu đá \r\ncơ lý";
            flexMauDa.Rows[1][10] = "Mẫu đá \r\nvật liệu";
            //Năng Xuât
            flexMauDa.Rows[1][11] = "Mẫu đá \r\ncơ lý";
            flexMauDa.Rows[1][12] = "Mẫu đá \r\nvật liệu";
        }
        private void FormatFlexMauCat()
        {
            flexMauCat.Rows[0].AllowMerging = true;
            flexMauCat.Rows[0].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauCat.Rows[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauCat.Cols[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauCat.Rows[1].HeightDisplay = 40;
            flexMauCat.Rows[2].Height = 20;

            flexMauCat.Rows[0][0] = "Mẫu\r\ncát";
            flexMauCat.Rows[1][0] = "Mẫu\r\ncát";
            //Mẫu Thực
            flexMauCat.Rows[1][1] = "Mẫu cát \r\nnền";
            flexMauCat.Rows[1][2] = "Mẫu cát \r\nvật liệu";
            //Mẫu Bốc
            flexMauCat.Rows[1][3] = "Mẫu cát \r\nnền";
            flexMauCat.Rows[1][4] = "Mẫu đá \r\nvật liệu";
            //Tổng mẫu thực hiện
            flexMauCat.Rows[1][5] = "Mẫu cát \r\nnền";
            flexMauCat.Rows[1][6] = "Mẫu cát \r\nvật liệu";
            //Tổng số mẫu không xuất bản
            flexMauCat.Rows[1][7] = "Mẫu cát \r\nnền";
            flexMauCat.Rows[1][8] = "Mẫu cát \r\nvật liệu";
            //Tổng số mẫu xuất bản
            flexMauCat.Rows[1][9] = "Mẫu cát \r\nnền";
            flexMauCat.Rows[1][10] = "Mẫu cát \r\nvật liệu";
          
        }
        private void FormatFlexMauNuoc()
        {
            flexMauNuoc.Rows[0].AllowMerging = true;
            flexMauNuoc.Rows[0].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauNuoc.Rows[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauNuoc.Cols[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexMauNuoc.Rows[1].HeightDisplay = 40;
            flexMauNuoc.Rows[2].Height = 20;

            flexMauNuoc.Rows[0][0] = "Mẫu\r\nnước";
            flexMauNuoc.Rows[1][0] = "Mẫu\r\nnước";
            //Mẫu Thực
            flexMauNuoc.Rows[1][1] = "Mẫu nước \r\năn mòn";
            flexMauNuoc.Rows[1][2] = "Mẫu nước \r\nvi sinh";
            //Mẫu Bốc
            flexMauNuoc.Rows[1][3] = "Mẫu nước \r\năn mòn";
            flexMauNuoc.Rows[1][4] = "Mẫu nước \r\nvi sinh";
            //Tổng mẫu thực hiện
            flexMauNuoc.Rows[1][5] = "Mẫu nước \r\năn mòn";
            flexMauNuoc.Rows[1][6] = "Mẫu nước \r\nvi sinh";
            //Tổng số mẫu không xuất bản
            flexMauNuoc.Rows[1][7] = "Mẫu nước \r\năn mòn";
            flexMauNuoc.Rows[1][8] = "Mẫu nước \r\nvi sinh";
            //Tổng số mẫu xuất bản
            flexMauNuoc.Rows[1][9] = "Mẫu nước \r\năn mòn";
            flexMauNuoc.Rows[1][10] = "Mẫu nước \r\nvi sinh";

        }
        private void FormatFlexThachHoc()
        {
            flexThachHoc.Cols[0].AllowMerging = true;
            flexThachHoc.Rows[0].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexThachHoc.Rows[0].HeightDisplay = 40;
            flexThachHoc.Rows[1].Height = 20;

            flexThachHoc.Rows[0][0] = "Thạch\r\nhọc";
            
            //Mẫu Thực
            flexThachHoc.Rows[0][1] = "Mẫu thực";
            //Mẫu Bốc
            flexThachHoc.Rows[0][2] = "Mẫu tham \r\nchiếu";
            //Tổng mẫu thực hiện
            flexThachHoc.Rows[0][3] = "Tổng số mẫu \r\nthực hiện";
            //Tổng số mẫu không xuất bản
            flexThachHoc.Rows[0][4] = "Tổng số mẫu \r\nkhông xuất bản";
            //Tổng số mẫu xuất bản
            flexThachHoc.Rows[0][5] = "Tổng số mẫu \r\nxuất bản";
           

        }
        private void FormatFlexThuyVan()
        {
            flexThuyVan.Cols[0].AllowMerging = true;
            flexThuyVan.Rows[0].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexThuyVan.Rows[0].HeightDisplay = 40;
            flexThuyVan.Rows[1].Height = 20;

            flexThuyVan.Rows[0][0] = "Thủy\r\nvăn";
            
            //Mẫu Thực
            flexThuyVan.Rows[0][1] = "Mẫu thực";
            //Mẫu Bốc
            flexThuyVan.Rows[0][2] = "Mẫu tham \r\nchiếu";
            //Tổng mẫu thực hiện
            flexThuyVan.Rows[0][3] = "Tổng số mẫu \r\nthực hiện";
            //Tổng số mẫu không xuất bản
            flexThuyVan.Rows[0][4] = "Tổng số mẫu \r\nkhông xuất bản";
            //Tổng số mẫu xuất bản
            flexThuyVan.Rows[0][5] = "Tổng số mẫu \r\nxuất bản";

        }
        private void FormatFlexCongDat()
        {
            flexCong.Rows[0].AllowMerging = true;
            flexCong.Cols[5].AllowMerging = true;
            flexCong.Cols[6].AllowMerging = true;
            flexCong.Cols[7].AllowMerging = true;
            flexCong.Cols[10].AllowMerging = true;
            flexCong.Rows[0].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexCong.Rows[1].TextAlign = C1.Win.C1FlexGrid.TextAlignEnum.CenterCenter;
            flexCong.Rows[1].HeightDisplay = 60;
            flexCong.Rows[2].HeightDisplay = 40;

            flexCong.Rows[1][1] = "Trong giờ";
            flexCong.Rows[1][2] = "Ngoài giờ";
            flexCong.Rows[1][3] = "Tham chiếu";
            flexCong.Rows[1][4] = "ISO";
            flexCong.Rows[0][5] = "Tổng công \r\nmẫu thực";
            flexCong.Rows[1][5] = "Tổng công \r\nmẫu thực";
            flexCong.Rows[0][6] = "Tổng công \r\nmẫu tham chiếu";
            flexCong.Rows[1][6] = "Tổng công \r\nmẫu tham chiếu";
            flexCong.Rows[1][7] = "Tổng số công";

            flexCong.Rows[1][8] = "Mẫu thí nghiệm";
            flexCong.Rows[1][9] = "Mẫu tham chiếu";
            flexCong.Rows[0][10] = "Năng suất \r\nbình quân";
            flexCong.Rows[1][10] = "Năng suất \r\nbình quân";


        }

        private void ClearControl()
        {
            cboGiaiDoan.Text = "";
            cboPhuTrach.Text = "";
            txtHangmuc.Text = "";
            dtThoiGian.Value = DateTime.Now;
            dtDenNgay.Value = DateTime.Now;
            cboCongTrinh.SelectedValue = "";
            txtSLThamchieu.Text = "0";
            txtSLThiNghiem.Text = "0";
            txtNSBQ.Text = "0";
            txtNhaNuoc.Value = 0;
            flexCong.Rows[2].Clear(ClearFlags.All);
            CellRange rg = flexMauDat.GetCellRange(2,0,2,flexMauDat.Cols.Count-1);
            flexMauDat.Clear(C1.Win.C1FlexGrid.ClearFlags.Content, rg);

            rg = flexMauDa.GetCellRange(2, 0, 2, flexMauDa.Cols.Count - 1);
            flexMauDa.Clear(C1.Win.C1FlexGrid.ClearFlags.Content, rg);

            rg = flexMauCat.GetCellRange(2, 0, 2, flexMauCat.Cols.Count - 1);
            flexMauCat.Clear(C1.Win.C1FlexGrid.ClearFlags.Content, rg);

            rg = flexMauNuoc.GetCellRange(2, 0, 2, flexMauNuoc.Cols.Count - 1);
            flexMauNuoc.Clear(C1.Win.C1FlexGrid.ClearFlags.Content, rg);

            rg = flexThachHoc.GetCellRange(1, 0, 1, flexThachHoc.Cols.Count - 1);
            flexThachHoc.Clear(C1.Win.C1FlexGrid.ClearFlags.Content, rg);

            rg = flexThuyVan.GetCellRange(1, 0, 1, flexThuyVan.Cols.Count - 1);
            flexThuyVan.Clear(C1.Win.C1FlexGrid.ClearFlags.Content, rg);

            rg = flexThiNghiem.GetCellRange(2, 0, 2, flexThiNghiem.Cols.Count - 1);
            flexThiNghiem.Clear(C1.Win.C1FlexGrid.ClearFlags.Content, rg);


            flexThiNghiem.Rows.Count = 1;
            flexNguoiThucHien.Rows.Count = 1;

          
        }
       
        private void StatusButton()
        {
            if (flagButton == Module.ClickButtonStatus.Them || flagButton == Module.ClickButtonStatus.Sua)
            {
                btnThem.Text = "&Ghi";
                btnSua.Text = "&Ngưng";
                btnXoa.Enabled = false;
                btnThoat.Enabled = false;
                cboCongTrinh.Focus();

            }
            else
            {
                btnThem.Text = "&Thêm";
                btnSua.Text = "&Sửa";
                btnXoa.Enabled = true;
                btnThoat.Enabled = true;
                cboCongTrinh.Focus();

            }
        }
        private void LoadVatlieuToCombo()
        {
            VatLieuBUS vatlieuBUS = new VatLieuBUS();
            cboVatlieu.ClearItems();
            cboVatlieu.DefColWidth = 100;
            cboVatlieu.AllowSort = true;
            cboVatlieu.DataSource = vatlieuBUS.GetListVatLieu();
            cboVatlieu.Columns[0].DataWidth = 0;


        }
        

        private void GetPhuTrach()
        {
            // Load the customer object from the existing XML file (if any)...
            if (File.Exists(XML_FILE_PHUTRACH) == true)
            {
                PhuTrach phutrach = ObjectXMLSerializer<PhuTrach>.Load(XML_FILE_PHUTRACH);
                this.LoadPhuTrachToCombo(phutrach);
            }
            
        }
        private void GetGiaiDoan()
        {
            // Load the customer object from the existing XML file (if any)...
            if (File.Exists(XML_FILE_GIAIDOAN) == true)
            {
                GiaiDoan giaidoan = ObjectXMLSerializer<GiaiDoan>.Load(XML_FILE_GIAIDOAN);
                this.LoadGiaiDoanToCombo(giaidoan);
            }

        }
        /// <summary>
        /// Load Nguyen quan len combo
        /// </summary>
        /// <param name="phutrach"></param>
        private void LoadPhuTrachToCombo(PhuTrach phutrach)
        {

            cboPhuTrach.ClearItems();
            cboPhuTrach.DefColWidth = 300;

            phutrach.Names.Sort();
            foreach (string Item in phutrach.Names)
            {
                cboPhuTrach.AddItem(Item);
            }
            cboPhuTrach.AllowSort = true;
            cboPhuTrach.Columns[0].Caption = "Name";
            


        }
        /// <summary>
        /// ADD nguyen quan vao file XML
        /// </summary>
        /// <returns></returns>
        private PhuTrach CreatePhuTrach()
        {
            PhuTrach phutrach = new PhuTrach();
            // Add nguyen quan as a collection of strings...
            phutrach.Names.Add(cboPhuTrach.Text);
            for (int i = 0; i < cboPhuTrach.ListCount; i++)
            {
                phutrach.Names.Add(cboPhuTrach.Columns[0].CellValue(i));
            }
            return phutrach;
        }

        private void GetCongTrinh()
        {
            CongTrinhBUS congtrinhBUS = new CongTrinhBUS();
            cboCongTrinh.ClearItems();
            cboCongTrinh.DefColWidth = 300;
            cboCongTrinh.AllowSort = true;
            cboCongTrinh.DataSource = congtrinhBUS.GetListCongTrinh();
           
        }
        /// <summary>
        /// Load Nguyen quan len combo
        /// </summary>
        /// <param name="giaidoan"></param>
        private void LoadGiaiDoanToCombo(GiaiDoan giaidoan)
        {

            cboGiaiDoan.ClearItems();
            cboGiaiDoan.DefColWidth = 300;

            giaidoan.Names.Sort();
            foreach (string Item in giaidoan.Names)
            {
                cboGiaiDoan.AddItem(Item);
            }
            cboGiaiDoan.AllowSort = true;
            cboGiaiDoan.Columns[0].Caption = "Name";
            


        }
        /// <summary>
        /// ADD nguyen quan vao file XML
        /// </summary>
        /// <returns></returns>
        private GiaiDoan CreateGiaiDoan()
        {
            GiaiDoan giaidoan = new GiaiDoan();
            // Add nguyen quan as a collection of strings...
            giaidoan.Names.Add(cboCongTrinh.Text);
            for (int i = 0; i < cboCongTrinh.ListCount; i++)
            {
                giaidoan.Names.Add(cboCongTrinh.Columns[0].CellValue(i));
            }
            return giaidoan;
        }

        #endregion

        private void SaveCombo()
        {
            if (cboPhuTrach.Row < 0 && cboPhuTrach.Text != "")
            {
                PhuTrach phutrach = this.CreatePhuTrach();
                //Save customer object to XML file using our ObjectXMLSerializer class...
                try
                {
                    ObjectXMLSerializer<PhuTrach>.Save(phutrach, XML_FILE_PHUTRACH);
                    LoadPhuTrachToCombo(phutrach);

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to save customer object!" + Environment.NewLine + Environment.NewLine + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
            if (cboGiaiDoan.Row < 0 && cboGiaiDoan.Text != "")
            {
                GiaiDoan giaidoan = this.CreateGiaiDoan();
                //Save customer object to XML file using our ObjectXMLSerializer class...
                try
                {
                    ObjectXMLSerializer<GiaiDoan>.Save(giaidoan, XML_FILE_GIAIDOAN);
                    LoadGiaiDoanToCombo(giaidoan);

                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to save customer object!" + Environment.NewLine + Environment.NewLine + ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
        }
        private Boolean CheckBeforeSave()
        {

            if (cboGiaiDoan.Text == "")
            {
                MessageBox.Show("Nhập giai đoạn.");
                return false;
            }
            if (cboCongTrinh.SelectedValue== null)
            {
                MessageBox.Show("Nhập công trình.");
                return false;
            }
            if (cboCongTrinh.Columns[2].Value.ToString() == "1")
            {
                MessageBox.Show("Công trình đã hoàn thành. vui lòng chọn công trình khác");
                return false;
            }

            if (flagButton == Module.ClickButtonStatus.Them  && GiaiDoanBUS.CheckGiaiDoan(cboGiaiDoan.Text, cboCongTrinh.SelectedValue.ToString(),txtHangmuc.Text).Rows.Count  >0)
            {
                MessageBox.Show("Giai đoạn " + cboGiaiDoan.Text + " đã được nhập vào công trình " + cboCongTrinh.Text);
                return false;
            }
            if (flagButton == Module.ClickButtonStatus.Sua  && GiaiDoanVO == null)
            {
                MessageBox.Show("Vui lòng chọn giai đoạn để sửa");
                return false;
            }
            return true;
        }
        private void SetValueToGiaiDoan()
        {
            GiaiDoanVO.TenGiaiDoan = cboGiaiDoan.Text;
            GiaiDoanVO.CongTrinh.KeySL = cboCongTrinh.SelectedValue.ToString();
            GiaiDoanVO.CongTrinh.TenCongTrinh = cboCongTrinh.Text;
            GiaiDoanVO.Hangmuc = txtHangmuc.Text;
            GiaiDoanVO.PhuTrach = cboPhuTrach.Text;
            GiaiDoanVO.ThoiGian = dtThoiGian.Value.Month.ToString() + "/" + dtThoiGian.Value.Day.ToString() + "/" + dtThoiGian.Value.Year.ToString();
            GiaiDoanVO.ThoiGianDen = dtDenNgay.Value.Month.ToString() + "/" + dtDenNgay.Value.Day.ToString() + "/" + dtDenNgay.Value.Year.ToString();

            GiaiDoanVO.SlThiNghiem = Convert.ToInt32(txtSLThiNghiem.Text);
            GiaiDoanVO.SlThamChieu = Convert.ToInt32(txtSLThamchieu.Text);
                      
            GiaiDoanVO.Dat_MT_Nguyendang = Convert.ToInt32(flexMauDat.Rows[2]["MTNguyenDang"]);
            GiaiDoanVO.Dat_MT_Roi = Convert.ToInt32(flexMauDat.Rows[2]["MTROI"]);
            GiaiDoanVO.Dat_MT_Vatlieu = Convert.ToInt32(flexMauDat.Rows[2]["MTVATLIEU"]);
            GiaiDoanVO.Dat_MT_Doam = Convert.ToInt32(flexMauDat.Rows[2]["MTDOAM"]);
            GiaiDoanVO.Dat_MT_Damchat = Convert.ToInt32(flexMauDat.Rows[2]["MTDAMCHAT"]);

            GiaiDoanVO.Dat_MB_Nguyendang = Convert.ToInt32(flexMauDat.Rows[2]["MBNGUYENDANG"]);
            GiaiDoanVO.Dat_MB_Roi = Convert.ToInt32(flexMauDat.Rows[2]["MBROI"]);
            GiaiDoanVO.Dat_MB_Vatlieu = Convert.ToInt32(flexMauDat.Rows[2]["MBVATLIEU"]);
            GiaiDoanVO.Dat_MB_Doam = Convert.ToInt32(flexMauDat.Rows[2]["MBDOAM"]);
            GiaiDoanVO.Dat_MB_Damchat = Convert.ToInt32(flexMauDat.Rows[2]["MBDAMCHAT"]);

            GiaiDoanVO.Dat_MKXB_Nguyendang = Convert.ToInt32(flexMauDat.Rows[2]["MKXBNGUYENDANG"]);
            GiaiDoanVO.Dat_MKXB_Roi = Convert.ToInt32(flexMauDat.Rows[2]["MKXBROI"]);
            GiaiDoanVO.Dat_MKXB_Vatlieu = Convert.ToInt32(flexMauDat.Rows[2]["MKXBVATLIEU"]);
            GiaiDoanVO.Dat_MKXB_Doam = Convert.ToInt32(flexMauDat.Rows[2]["MKXBDOAM"]);
            GiaiDoanVO.Dat_MKXB_Damchat = Convert.ToInt32(flexMauDat.Rows[2]["MKXBDAMCHAT"]);

            GiaiDoanVO.Da_MT_Coly = Convert.ToInt32(flexMauDa.Rows[2]["MTCOLY"]);
            GiaiDoanVO.Da_MT_Vatlieu = Convert.ToInt32(flexMauDa.Rows[2]["MTVATLIEU"]);
            GiaiDoanVO.Da_MB_Coly = Convert.ToInt32(flexMauDa.Rows[2]["MBCOLY"]);
            GiaiDoanVO.Da_MB_Vatlieu = Convert.ToInt32(flexMauDa.Rows[2]["MBVATLIEU"]);
            GiaiDoanVO.Da_MKXB_Coly = Convert.ToInt32(flexMauDa.Rows[2]["MKXBCOLY"]);
            GiaiDoanVO.Da_MKXB_Vatlieu = Convert.ToInt32(flexMauDa.Rows[2]["MKXBVATLIEU"]);

            GiaiDoanVO.Cat_MT_Catnen = Convert.ToInt32(flexMauCat.Rows[2]["MTCATNEN"]);
            GiaiDoanVO.Cat_MT_Vatlieu = Convert.ToInt32(flexMauCat.Rows[2]["MTVATLIEU"]);
            GiaiDoanVO.Cat_MB_Catnen = Convert.ToInt32(flexMauCat.Rows[2]["MBCATNEN"]);
            GiaiDoanVO.Cat_MB_Vatlieu = Convert.ToInt32(flexMauCat.Rows[2]["MBVATLIEU"]);
            GiaiDoanVO.Cat_MKXB_Catnen = Convert.ToInt32(flexMauCat.Rows[2]["MKXBCATNEN"]);
            GiaiDoanVO.Cat_MKXB_Vatlieu = Convert.ToInt32(flexMauCat.Rows[2]["MKXBVATLIEU"]);

            GiaiDoanVO.Nuoc_MT_Betong = Convert.ToInt32(flexMauNuoc.Rows[2]["MTBETONG"]);
            GiaiDoanVO.Nuoc_MT_Visinh = Convert.ToInt32(flexMauNuoc.Rows[2]["MTVISINH"]);
            GiaiDoanVO.Nuoc_MB_Betong = Convert.ToInt32(flexMauNuoc.Rows[2]["MBBETONG"]);
            GiaiDoanVO.Nuoc_MB_Visinh = Convert.ToInt32(flexMauNuoc.Rows[2]["MBVISINH"]);
            GiaiDoanVO.Nuoc_MKXB_Betong = Convert.ToInt32(flexMauNuoc.Rows[2]["MKXBBETONG"]);
            GiaiDoanVO.Nuoc_MKXB_Visinh = Convert.ToInt32(flexMauNuoc.Rows[2]["MKXBVISINH"]);


            GiaiDoanVO.Thachhoc_MT = Convert.ToInt32(flexThachHoc.Rows[1]["MT"]);
            GiaiDoanVO.Thachhoc_MB = Convert.ToInt32(flexThachHoc.Rows[1]["MB"]);
            GiaiDoanVO.Thachhoc_MKXB = Convert.ToInt32(flexThachHoc.Rows[1]["MKXB"]);

            GiaiDoanVO.Thuyvan_MT = Convert.ToInt32(flexThuyVan.Rows[1]["MT"]);
            GiaiDoanVO.Thuyvan_MB = Convert.ToInt32(flexThuyVan.Rows[1]["MB"]);
            GiaiDoanVO.Thuyvan_MKXB = Convert.ToInt32(flexThuyVan.Rows[1]["MKXB"]);

            GiaiDoanVO.Cong_MT_Tronggio = Convert.ToDouble(flexCong.Rows[2]["MTTRONGGIO"]);
            GiaiDoanVO.Cong_MT_Ngoaigio = Convert.ToDouble(flexCong.Rows[2]["MTNGOAIGIO"]);
            GiaiDoanVO.Cong_MB_Boc = Convert.ToDouble(flexCong.Rows[2]["MBBOC"]);
            GiaiDoanVO.Cong_MB_ISO = Convert.ToDouble(flexCong.Rows[2]["MBISO"]);

            GiaiDoanVO.NSThiNghiem = Convert.ToDouble(flexCong.Rows[2]["NXTHINGHIEM"]);
            GiaiDoanVO.NSThamChieu = Convert.ToDouble(flexCong.Rows[2]["NXTHAMCHIEU"]);
            GiaiDoanVO.NSBQ = Convert.ToDouble(flexCong.Rows[2]["NSBQ"]);


            GiaiDoanVO.Cong_Nhanuoc = Convert.ToDouble(txtNhaNuoc.Text);

            GiaiDoanVO.LstGiaDoanNguoiThucHien.Clear();

            for (int i = 1; i < flexNguoiThucHien.Rows.Count-1; i++)
            {
                if (flexNguoiThucHien.Rows[i]["NguoiThucHien"] != null || flexNguoiThucHien.Rows[i]["ThiNghiemChinh"] != null)
                {
                    GiaiDoanVO.LstGiaDoanNguoiThucHien.Add(new GiaiDoanNguoiThucHienVO(flexNguoiThucHien.Rows[i]["NguoiThucHien"].ToString(), flexNguoiThucHien.Rows[i]["ThiNghiemChinh"].ToString(), flexNguoiThucHien.Rows[i]["Hieuqua"].ToString()));
                }
            }
            
            //GiaiDoanVO.LstGiaiDoanDetail = lstGiaiDoanDetailVO;
            //GiaiDoanVO.LstGiaDoanNguoiThucHien = lstGiaiDoanNguoiThucHienVO;
            
        }
        public object ReturnObject(double input)
        {
            if (input == 0)
            {
                return "";
            }
            else
            {
                return input;
            }
        }
        public void SetValueToControl()
        {
            cboGiaiDoan.Text = GiaiDoanVO.TenGiaiDoan;
            cboCongTrinh.SelectedValue  = GiaiDoanVO.CongTrinh.KeySL;
            cboPhuTrach.Text  = GiaiDoanVO.PhuTrach;
            txtHangmuc.Text = GiaiDoanVO.Hangmuc;
            dtThoiGian.Value = Convert.ToDateTime(GiaiDoanVO.ThoiGian);
            dtDenNgay.Value = Convert.ToDateTime(GiaiDoanVO.ThoiGianDen);
            
            txtSLThiNghiem.Text = GiaiDoanVO.SlThiNghiem.ToString();
            txtSLThamchieu.Text = GiaiDoanVO.SlThamChieu.ToString();

            flexMauDat.Rows[2]["MTNguyenDang"] = ReturnObject(GiaiDoanVO.Dat_MT_Nguyendang);
            flexMauDat.Rows[2]["MTROI"] = ReturnObject(GiaiDoanVO.Dat_MT_Roi);
            flexMauDat.Rows[2]["MTVATLIEU"] = ReturnObject(GiaiDoanVO.Dat_MT_Vatlieu);
            flexMauDat.Rows[2]["MTDOAM"] = ReturnObject(GiaiDoanVO.Dat_MT_Doam);
            flexMauDat.Rows[2]["MTDAMCHAT"] = ReturnObject(GiaiDoanVO.Dat_MT_Damchat);
            flexMauDat.Rows[2]["MBNGUYENDANG"] = ReturnObject(GiaiDoanVO.Dat_MB_Nguyendang);
            flexMauDat.Rows[2]["MBROI"] = ReturnObject(GiaiDoanVO.Dat_MB_Roi);
            flexMauDat.Rows[2]["MBVATLIEU"] = ReturnObject(GiaiDoanVO.Dat_MB_Vatlieu);
            flexMauDat.Rows[2]["MBDOAM"] = ReturnObject(GiaiDoanVO.Dat_MB_Doam);
            flexMauDat.Rows[2]["MBDAMCHAT"] = ReturnObject(GiaiDoanVO.Dat_MB_Damchat);
            flexMauDat.Rows[2]["MKXBNGUYENDANG"] = ReturnObject(GiaiDoanVO.Dat_MKXB_Nguyendang);
            flexMauDat.Rows[2]["MKXBROI"] = ReturnObject(GiaiDoanVO.Dat_MKXB_Roi);
            flexMauDat.Rows[2]["MKXBVATLIEU"] = ReturnObject(GiaiDoanVO.Dat_MKXB_Vatlieu);
            flexMauDat.Rows[2]["MKXBDOAM"] = ReturnObject(GiaiDoanVO.Dat_MKXB_Doam);
            flexMauDat.Rows[2]["MKXBDAMCHAT"] = ReturnObject(GiaiDoanVO.Dat_MKXB_Damchat);

            flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMNGUYENDANG"] = ReturnObject(
                  Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTNGUYENDANG"]) +
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBNGUYENDANG"]));
            flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMROI"] = ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTROI"]) +
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBROI"]));
            flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMVATLIEU"] =ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTVATLIEU"]) +
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBVATLIEU"]));
            flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMDOAM"] = ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTDOAM"]) +
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBDOAM"]));
            flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMDAMCHAT"] = ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTDAMCHAT"]) +
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBDAMCHAT"]));

            flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBNGUYENDANG"] = ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMNGUYENDANG"]) -
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBNGUYENDANG"]));
            flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBROI"] = ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMROI"]) -
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBROI"]));
            flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBVATLIEU"] = ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMVATLIEU"]) -
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBVATLIEU"]));
            flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBDOAM"] = ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMDOAM"]) -
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBDOAM"]));
            flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBDAMCHAT"] = ReturnObject(
               Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMDAMCHAT"]) -
                Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBDAMCHAT"]));



            flexMauDa.Rows[2]["MTCOLY"] = ReturnObject(GiaiDoanVO.Da_MT_Coly) ;
            flexMauDa.Rows[2]["MTVATLIEU"] = ReturnObject(GiaiDoanVO.Da_MT_Vatlieu);
            flexMauDa.Rows[2]["MBCOLY"] = ReturnObject(GiaiDoanVO.Da_MB_Coly);
            flexMauDa.Rows[2]["MBVATLIEU"] = ReturnObject(GiaiDoanVO.Da_MB_Vatlieu) ;
            flexMauDa.Rows[2]["MKXBCOLY"] = ReturnObject(GiaiDoanVO.Da_MKXB_Coly);
            flexMauDa.Rows[2]["MKXBVATLIEU"] = ReturnObject(GiaiDoanVO.Da_MKXB_Vatlieu);

            flexMauDa.Rows[flexMauDa.Selection.TopRow]["TMCOLY"] =ReturnObject(
                 Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MTCOLY"]) +
                  Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MBCOLY"]));
            flexMauDa.Rows[flexMauDa.Selection.TopRow]["TMVATLIEU"] =ReturnObject(
                 Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MTVATLIEU"]) +
                  Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MBVATLIEU"]));

            flexMauDa.Rows[flexMauDa.Selection.TopRow]["MXBCOLY"] =ReturnObject(
                Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["TMCOLY"]) -
                 Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MKXBCOLY"]));

            flexMauDa.Rows[flexMauDa.Selection.TopRow]["MXBVATLIEU"] =ReturnObject(
                Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["TMVATLIEU"]) -
                 Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MKXBVATLIEU"]));

            flexMauDa.Rows[flexMauDa.Selection.TopRow]["NXCOLY"] =ReturnObject(
                Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MKXBCOLY"]) -
                 Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MXBCOLY"]));

            flexMauDa.Rows[flexMauDa.Selection.TopRow]["NXVATLIEU"] =ReturnObject(
               Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MKXBVATLIEU"]) -
                Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MXBVATLIEU"]));


            flexMauCat.Rows[2]["MTCATNEN"] = ReturnObject(GiaiDoanVO.Cat_MT_Catnen);
            flexMauCat.Rows[2]["MTVATLIEU"] = ReturnObject(GiaiDoanVO.Cat_MT_Vatlieu);
            flexMauCat.Rows[2]["MBCATNEN"] = ReturnObject(GiaiDoanVO.Cat_MB_Catnen);
            flexMauCat.Rows[2]["MBVATLIEU"]=ReturnObject(GiaiDoanVO.Cat_MB_Vatlieu);
            flexMauCat.Rows[2]["MKXBCATNEN"] = ReturnObject(GiaiDoanVO.Cat_MKXB_Catnen);
            flexMauCat.Rows[2]["MKXBVATLIEU"] = ReturnObject(GiaiDoanVO.Cat_MKXB_Vatlieu);

            flexMauCat.Rows[flexMauCat.Selection.TopRow]["TMCATNEN"] =ReturnObject(
                 Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MTCATNEN"]) +
                  Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MBCATNEN"]));
            flexMauCat.Rows[flexMauCat.Selection.TopRow]["TMVATLIEU"] =ReturnObject(
                 Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MTVATLIEU"]) +
                  Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MBVATLIEU"]));
            flexMauCat.Rows[flexMauCat.Selection.TopRow]["MXBCATNEN"] =ReturnObject(
                 Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["TMCATNEN"]) -
                  Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MKXBCATNEN"]));
            flexMauCat.Rows[flexMauCat.Selection.TopRow]["MXBVATLIEU"] =ReturnObject(
                 Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["TMVATLIEU"]) -
                  Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MKXBVATLIEU"]));
            
            flexMauNuoc.Rows[2]["MTBETONG"] = ReturnObject(GiaiDoanVO.Nuoc_MT_Betong);
            flexMauNuoc.Rows[2]["MTVISINH"] = ReturnObject(GiaiDoanVO.Nuoc_MT_Visinh) ;
            flexMauNuoc.Rows[2]["MBBETONG"] = ReturnObject(GiaiDoanVO.Nuoc_MB_Betong);
            flexMauNuoc.Rows[2]["MBVISINH"] = ReturnObject(GiaiDoanVO.Nuoc_MB_Visinh); 
            flexMauNuoc.Rows[2]["MKXBBETONG"]=ReturnObject(GiaiDoanVO.Nuoc_MKXB_Betong) ;
            flexMauNuoc.Rows[2]["MKXBVISINH"]=ReturnObject(GiaiDoanVO.Nuoc_MKXB_Visinh) ;

            flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["TMBETONG"] =ReturnObject(
                 Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MTBETONG"]) +
                  Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MBBETONG"]));
            flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["TMVISINH"] = ReturnObject(
                 Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MTVISINH"]) +
                  Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MBVISINH"]));
            flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MXBBETONG"] =ReturnObject(
                 Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["TMBETONG"]) -
                  Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MKXBBETONG"]));
            flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MXBVISINH"] =ReturnObject(
                 Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["TMVISINH"]) -
                  Convert.ToInt32(flexMauNuoc.Rows[flexMauCat.Selection.TopRow]["MKXBVISINH"]));

            flexThachHoc.Rows[1]["MT"]=ReturnObject(GiaiDoanVO.Thachhoc_MT) ;
            flexThachHoc.Rows[1]["MB"]=ReturnObject(GiaiDoanVO.Thachhoc_MB) ;
            flexThachHoc.Rows[1]["MKXB"]=ReturnObject(GiaiDoanVO.Thachhoc_MKXB) ;

            flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["TM"] =ReturnObject(
                 Convert.ToInt32(flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["MT"]) +
                  Convert.ToInt32(flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["MB"]));
            flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["MXB"] =ReturnObject(
                 Convert.ToInt32(flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["TM"]) -
                  Convert.ToInt32(flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["MKXB"]));


            flexThuyVan.Rows[1]["MT"] = ReturnObject(GiaiDoanVO.Thuyvan_MT) ;
            flexThuyVan.Rows[1]["MB"] = ReturnObject(GiaiDoanVO.Thuyvan_MB);
            flexThuyVan.Rows[1]["MKXB"] = ReturnObject(GiaiDoanVO.Thuyvan_MKXB) ;

            flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["TM"] =ReturnObject(
               Convert.ToInt32(flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["MT"]) +
                Convert.ToInt32(flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["MB"]));
            flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["MXB"] =ReturnObject(
                 Convert.ToInt32(flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["TM"]) -
                  Convert.ToInt32(flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["MKXB"]));

            flexCong.Rows[2]["MTTRONGGIO"]=ReturnObject(GiaiDoanVO.Cong_MT_Tronggio) ;
            flexCong.Rows[2]["MTNGOAIGIO"] = ReturnObject(GiaiDoanVO.Cong_MT_Ngoaigio);
            flexCong.Rows[2]["MBBOC"] = ReturnObject(GiaiDoanVO.Cong_MB_Boc);
            flexCong.Rows[2]["MBISO"] = ReturnObject(GiaiDoanVO.Cong_MB_ISO);
            txtNhaNuoc.Value   = GiaiDoanVO.Cong_Nhanuoc;

            flexCong.Rows[2]["TCMT"] =ReturnObject(
                  Convert.ToDouble(flexCong.Rows[2]["MTTrongGio"]) +
                   Convert.ToDouble(flexCong.Rows[2]["MTNgoaiGio"]));
            flexCong.Rows[2]["TCMB"] =ReturnObject(
               Convert.ToDouble(flexCong.Rows[2]["MBBOC"]) +
                Convert.ToDouble(flexCong.Rows[2]["MBISO"]));
            flexCong.Rows[2]["TC"] =ReturnObject(
               Convert.ToDouble(flexCong.Rows[2]["TCMT"]) +
                Convert.ToDouble(flexCong.Rows[2]["TCMB"]));

            if (txtSLThiNghiem.Text != "0")
            {
                flexCong.Rows[2]["NXTHINGHIEM"] =
                   Convert.ToDouble(flexCong.Rows[2]["TCMT"]) / Convert.ToInt32(txtSLThiNghiem.Text);
            }
            if (txtSLThamchieu.Text != "0")
            {
                flexCong.Rows[2]["NXTHAMCHIEU"] =
                   Convert.ToDouble(flexCong.Rows[2]["TCMB"]) / Convert.ToInt32(txtSLThamchieu.Text);
            }
            if (txtSLThiNghiem.Text != "0" || txtSLThamchieu.Text != "0")
            {
                flexCong.Rows[2]["NSBQ"] =
                     Convert.ToDouble(flexCong.Rows[2]["TC"]) / (Convert.ToInt32(txtSLThamchieu.Text) + Convert.ToInt32(txtSLThiNghiem.Text));
                txtNSBQ.Text = String.Format("{0:0.#}", flexCong.Rows[2]["NSBQ"]); 
            }
            
            int i = 1;

            flexNguoiThucHien.Rows.Count = 1;
            foreach (GiaiDoanNguoiThucHienVO giaidoanNguoiThucHien in GiaiDoanVO.LstGiaDoanNguoiThucHien)
            {
                flexNguoiThucHien.Rows[i]["NguoiThucHien"] = giaidoanNguoiThucHien.ThucHien;
                flexNguoiThucHien.Rows[i]["ThiNghiemChinh"] = giaidoanNguoiThucHien.ThiNghiem;
                flexNguoiThucHien.Rows[i]["Hieuqua"] = giaidoanNguoiThucHien.KetQua;
                flexNguoiThucHien.Rows.Count = flexNguoiThucHien.Rows.Count + 1;
                i++;
                
            }
            
            //GiaiDoanVO.LstGiaiDoanDetail = lstGiaiDoanDetailVO;
            //GiaiDoanVO.LstGiaDoanNguoiThucHien = lstGiaiDoanNguoiThucHienVO;

            cboVatlieu.Text = "";
            flexThiNghiem.Rows.Count = 1;
            flexThiNghiem.Cols.Count = 1;

        }
        public void btnThem_Click(object sender, EventArgs e)
        {
            switch (flagButton)
            {
                case Module.ClickButtonStatus.Ngung:
                    flagButton = Module.ClickButtonStatus.Them;
                    GiaiDoanVO = new GiaiDoanVO();
                    cboCongTrinh.Enabled = true;
                    ClearControl();
                    break;
                case Module.ClickButtonStatus.Them:
                    if (CheckBeforeSave() == false) { return; }
                    SetValueToGiaiDoan();
                    GiaiDoanVO = GiaiDoanBUS.InsertRecord(GiaiDoanVO);
                    if (GiaiDoanVO == null)
                    {
                        MessageBox.Show("Không ghi được dữ liệu", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    //ClearControl();
                    flagButton = Module.ClickButtonStatus.Ngung;
                    break;
                case Module.ClickButtonStatus.Sua:
                    if (CheckBeforeSave() == false) { return; }
                    SetValueToGiaiDoan();
                    GiaiDoanBUS.UpdateRecord(GiaiDoanVO);
                    flagButton = Module.ClickButtonStatus.Ngung;
                    break;


            }
            StatusButton();
        }

        public void btnSua_Click(object sender, EventArgs e)
        {
            switch (flagButton)
            {
                case Module.ClickButtonStatus.Ngung:
                    cboCongTrinh.Enabled = false;
                    flagButton = Module.ClickButtonStatus.Sua;
                    break;
                case Module.ClickButtonStatus.Sua:
                    cboCongTrinh.Enabled = true;
                    flagButton = Module.ClickButtonStatus.Ngung;
                    break;
                case Module.ClickButtonStatus.Them:
                    cboCongTrinh.Enabled = true;
                    flagButton = Module.ClickButtonStatus.Ngung;
                    break;

            }
            StatusButton();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (cboCongTrinh.Columns[2].Value.ToString() == "1")
            {
                MessageBox.Show("Công trình đã hoàn thành. Bạn không được xóa");
                return;
            }
            GiaiDoanBUS.DeleteRecord(GiaiDoanVO.KeySL);
            ClearControl();
              
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        
        private void flexCong_AfterEdit(object sender, RowColEventArgs e)
        {
            if (flexCong.Selection.TopRow == 2)
            {
                flexCong.Rows[flexCong.Selection.TopRow]["TCMT"] =
                  Convert.ToDouble(flexCong.Rows[flexCong.Selection.TopRow]["MTTrongGio"]) +
                   Convert.ToDouble(flexCong.Rows[flexCong.Selection.TopRow]["MTNgoaiGio"]);
                flexCong.Rows[flexCong.Selection.TopRow]["TCMB"] =
                   Convert.ToDouble(flexCong.Rows[flexCong.Selection.TopRow]["MBBOC"]) +
                    Convert.ToDouble(flexCong.Rows[flexCong.Selection.TopRow]["MBISO"]);
                flexCong.Rows[flexCong.Selection.TopRow]["TC"] =
                   Convert.ToDouble(flexCong.Rows[flexCong.Selection.TopRow]["TCMT"]) +
                    Convert.ToDouble(flexCong.Rows[flexCong.Selection.TopRow]["TCMB"]);

                if (txtSLThiNghiem.Text != "0")
                {
                    flexCong.Rows[2]["NXTHINGHIEM"] =
                       Convert.ToDouble(flexCong.Rows[2]["TCMT"]) / Convert.ToInt32(txtSLThiNghiem.Text);
                }
                if (txtSLThamchieu.Text != "0")
                {
                    flexCong.Rows[2]["NXTHAMCHIEU"] =
                       Convert.ToDouble(flexCong.Rows[2]["TCMB"]) / Convert.ToInt32(txtSLThamchieu.Text);
                }
                if (txtSLThiNghiem.Text != "0" || txtSLThamchieu.Text != "0")
                {
                    flexCong.Rows[2]["NSBQ"] =
                         Convert.ToDouble(flexCong.Rows[2]["TC"]) / (Convert.ToInt32(txtSLThamchieu.Text) + Convert.ToInt32(txtSLThiNghiem.Text));
                    txtNSBQ.Text = String.Format("{0:0.#}", flexCong.Rows[2]["NSBQ"]);
                }

                
            }
        }
        
        private void FortmatFlexMauVatLieu(string keySL)
        {
            MauVatLieuBUS mauvatlieuBUS = new MauVatLieuBUS();
            List<MauVatLieuVO> lstMauVatLieu;
            flexThiNghiem.Clear(ClearFlags.All);
            lstMauVatLieu = mauvatlieuBUS.GetMauVatLieuByKeySL(keySL);
            flexThiNghiem.Cols.Count  = lstMauVatLieu.Count + 2;
            flexThiNghiem.Cols[0].Width = 150;
            for (int i = 1; i < flexThiNghiem.Cols.Count-1 ; i++)
            {
                flexThiNghiem.Cols[i].Name = lstMauVatLieu[i - 1].KeySL;
                flexThiNghiem.Cols[i].Caption  = lstMauVatLieu[i - 1].TenMauVatLieu;
                flexThiNghiem.Cols[i].Width = 150;
                flexThiNghiem.Cols[i].DataType = typeof(bool);
            }
            flexThiNghiem.Cols[flexThiNghiem.Cols.Count - 1].Name = "KEYSL";
            flexThiNghiem.Cols[flexThiNghiem.Cols.Count - 1].Visible = false;
            
        }
        private void FortmatFlexThiNghiem(string keySL)
        {
            ThiNghiemBUS thinghiemBUS = new ThiNghiemBUS();
            List<ThiNghiemVO> lstThiNghiem;
            
            lstThiNghiem = thinghiemBUS.GetThiNghiemByKeySL(keySL);
            flexThiNghiem.Rows.Count = lstThiNghiem.Count + 1;
            for (int i = 1; i < flexThiNghiem.Rows.Count; i++)
            {
                flexThiNghiem.Cols[0][i] = lstThiNghiem[i - 1].TenThiNghiem;
                flexThiNghiem.Cols[flexThiNghiem.Cols.Count - 1][i] = lstThiNghiem[i - 1].KeySL;
               
            }
            flexThiNghiem.Rows.Count = flexThiNghiem.Rows.Count + 1;
            flexThiNghiem.Rows[flexThiNghiem.Rows.Count - 1].StyleFixed = flexThiNghiem.Rows[0].StyleFixed;
        }
        private void cboVatlieu_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cboVatlieu.SelectedValue != null)
            {
                FortmatFlexMauVatLieu(cboVatlieu.SelectedValue.ToString());
                FortmatFlexThiNghiem(cboVatlieu.SelectedValue.ToString());
                SetVaLueInFlexThiNghiem();
            }
        }
        private void SetVaLueInFlexThiNghiem()
        {
            for (int i = 1; i < flexThiNghiem.Rows.Count-1; i++)
            {
                for (int j = 1; j < flexThiNghiem.Cols.Count - 1; j++)
                {
                    foreach (GiaiDoanDetailVO GiaiDoandetailVO in GiaiDoanVO.LstGiaiDoanDetail)
                    {
                        if (flexThiNghiem.Cols[j].Name == GiaiDoandetailVO.KeySLMauVatLieu &&
                            flexThiNghiem.Rows[i][flexThiNghiem.Cols.Count-1].ToString() == GiaiDoandetailVO.KeySLThiNghiem)
                        {
                            flexThiNghiem.Rows[i][j] = 1;
                            break;
                        }
                    }
                }
            }
           
        }
        
        private static bool FindDetail(GiaiDoanDetailVO GiaiDoandetailVO,string keySLVatLieu)
        {
            if (GiaiDoandetailVO.KeySLVatLieu == keySLVatLieu)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

      
        private void flexMauDa_AfterEdit(object sender, RowColEventArgs e)
        {
            if (flexMauDa.Selection.TopRow == 2)
            {
                flexMauDa.Rows[flexMauDa.Selection.TopRow]["TMCOLY"] =
                 Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MTCOLY"]) +
                  Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MBCOLY"]);

                flexMauDa.Rows[flexMauDa.Selection.TopRow]["TMVATLIEU"] =
                     Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MTVATLIEU"]) +
                      Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MBVATLIEU"]);

                flexMauDa.Rows[flexMauDa.Selection.TopRow]["MXBCOLY"] =
                    Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["TMCOLY"]) -
                     Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MKXBCOLY"]);

                flexMauDa.Rows[flexMauDa.Selection.TopRow]["MXBVATLIEU"] =
                    Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["TMVATLIEU"]) -
                     Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MKXBVATLIEU"]);

                flexMauDa.Rows[flexMauDa.Selection.TopRow]["NXCOLY"] =
                    Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MKXBCOLY"]) -
                     Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MXBCOLY"]);

                flexMauDa.Rows[flexMauDa.Selection.TopRow]["NXVATLIEU"] =
                   Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MKXBVATLIEU"]) -
                    Convert.ToInt32(flexMauDa.Rows[flexMauDa.Selection.TopRow]["MXBVATLIEU"]);
                SetTong();
            }
        }
        private void flexMauCat_AfterEdit(object sender, RowColEventArgs e)
        {
            if (flexMauCat.Selection.TopRow == 2)
            {
                flexMauCat.Rows[flexMauCat.Selection.TopRow]["TMCATNEN"] =
                Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MTCATNEN"]) +
                 Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MBCATNEN"]);
                flexMauCat.Rows[flexMauCat.Selection.TopRow]["TMVATLIEU"] =
                     Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MTVATLIEU"]) +
                      Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MBVATLIEU"]);
                flexMauCat.Rows[flexMauCat.Selection.TopRow]["MXBCATNEN"] =
                     Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["TMCATNEN"]) -
                      Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MKXBCATNEN"]);
                flexMauCat.Rows[flexMauCat.Selection.TopRow]["MXBVATLIEU"] =
                     Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["TMVATLIEU"]) -
                      Convert.ToInt32(flexMauCat.Rows[flexMauCat.Selection.TopRow]["MKXBVATLIEU"]);
                SetTong();
            }
        }

        private void flexMauNuoc_AfterEdit(object sender, RowColEventArgs e)
        {
            if (flexMauNuoc.Selection.TopRow == 2)
            {

                flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["TMBETONG"] =
                     Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MTBETONG"]) +
                      Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MBBETONG"]);
                flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["TMVISINH"] =
                     Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MTVISINH"]) +
                      Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MBVISINH"]);
                flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MXBBETONG"] =
                     Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["TMBETONG"]) -
                      Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MKXBBETONG"]);
                flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["MXBVISINH"] =
                     Convert.ToInt32(flexMauNuoc.Rows[flexMauNuoc.Selection.TopRow]["TMVISINH"]) -
                      Convert.ToInt32(flexMauNuoc.Rows[flexMauCat.Selection.TopRow]["MKXBVISINH"]);
                SetTong();
            }
        }

        private void flexThachHoc_AfterEdit(object sender, RowColEventArgs e)
        {
            if (flexThachHoc.Selection.TopRow == 1)
            {
                flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["TM"] =
                    Convert.ToInt32(flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["MT"]) +
                     Convert.ToInt32(flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["MB"]);
                flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["MXB"] =
                     Convert.ToInt32(flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["TM"]) -
                      Convert.ToInt32(flexThachHoc.Rows[flexThachHoc.Selection.TopRow]["MKXB"]);
                SetTong();
            }
        }

        private void flexThuyVan_AfterEdit(object sender, RowColEventArgs e)
        {
            if (flexThuyVan.Selection.TopRow == 1)
            {
                flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["TM"] =
               Convert.ToInt32(flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["MT"]) +
                Convert.ToInt32(flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["MB"]);
                flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["MXB"] =
                     Convert.ToInt32(flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["TM"]) -
                      Convert.ToInt32(flexThuyVan.Rows[flexThuyVan.Selection.TopRow]["MKXB"]);
                SetTong();
            }
        }
       
        private void SetTong()
        {
            txtSLThiNghiem.Text = (Convert.ToInt32(flexMauDat.Rows[2]["MTNguyenDang"]) +
           Convert.ToInt32(flexMauDat.Rows[2]["MTROI"]) +
           Convert.ToInt32(flexMauDat.Rows[2]["MTVATLIEU"]) +
           Convert.ToInt32(flexMauDat.Rows[2]["MTDOAM"]) +
           Convert.ToInt32(flexMauDat.Rows[2]["MTDAMCHAT"]) +
           Convert.ToInt32(flexMauDa.Rows[2]["MTCOLY"]) +
           Convert.ToInt32(flexMauDa.Rows[2]["MTVATLIEU"]) +
           Convert.ToInt32(flexMauCat.Rows[2]["MTCATNEN"]) +
           Convert.ToInt32(flexMauCat.Rows[2]["MTVATLIEU"]) +
           Convert.ToInt32(flexMauNuoc.Rows[2]["MTBETONG"]) +
           Convert.ToInt32(flexMauNuoc.Rows[2]["MTVISINH"]) +
           Convert.ToInt32(flexThachHoc.Rows[1]["MT"]) +
           Convert.ToInt32(flexThuyVan.Rows[1]["MT"])).ToString();

           txtSLThamchieu.Text = (Convert.ToInt32(flexMauDat.Rows[2]["MBNguyenDang"]) +
           Convert.ToInt32(flexMauDat.Rows[2]["MBROI"]) +
           Convert.ToInt32(flexMauDat.Rows[2]["MBVATLIEU"]) +
           Convert.ToInt32(flexMauDat.Rows[2]["MBDOAM"]) +
            Convert.ToInt32(flexMauDat.Rows[2]["MBDAMCHAT"]) +
           Convert.ToInt32(flexMauDa.Rows[2]["MBCOLY"]) +
           Convert.ToInt32(flexMauDa.Rows[2]["MBVATLIEU"]) +
           Convert.ToInt32(flexMauCat.Rows[2]["MBCATNEN"]) +
           Convert.ToInt32(flexMauCat.Rows[2]["MBVATLIEU"]) +
           Convert.ToInt32(flexMauNuoc.Rows[2]["MBBETONG"]) +
           Convert.ToInt32(flexMauNuoc.Rows[2]["MBVISINH"]) +
           Convert.ToInt32(flexThachHoc.Rows[1]["MB"]) +
           Convert.ToInt32(flexThuyVan.Rows[1]["MB"])).ToString();

           if (txtSLThiNghiem.Text != "0")
           {
               flexCong.Rows[2]["NXTHINGHIEM"] =
                  Convert.ToDouble(flexCong.Rows[2]["TCMT"]) / Convert.ToInt32(txtSLThiNghiem.Text);
           }
           if (txtSLThamchieu.Text != "0")
           {
               flexCong.Rows[2]["NXTHAMCHIEU"] =
                  Convert.ToDouble(flexCong.Rows[2]["TCMB"]) / Convert.ToInt32(txtSLThamchieu.Text);
           }
           if (txtSLThiNghiem.Text != "0" || txtSLThamchieu.Text != "0")
           {
               flexCong.Rows[2]["NSBQ"] =
                    Convert.ToDouble(flexCong.Rows[2]["TC"]) / (Convert.ToInt32(txtSLThamchieu.Text) + Convert.ToInt32(txtSLThiNghiem.Text));
               txtNSBQ.Text = String.Format("{0:0.#}", flexCong.Rows[2]["NSBQ"]);
           }

        }
        private void flexThiNghiem_AfterEdit(object sender, RowColEventArgs e)
        {
            if (e.Row < flexThiNghiem.Rows.Count - 1)
            {
                GiaiDoanDetailVO GiaiDoandetail1VO;
                GiaiDoanDetailVO result = GiaiDoanVO.LstGiaiDoanDetail.Find(
                    delegate(GiaiDoanDetailVO GiaiDoandetailVO)
                    {
                        return GiaiDoandetailVO.KeySLMauVatLieu == flexThiNghiem.Cols[e.Col].Name && 
                            GiaiDoandetailVO.KeySLThiNghiem == flexThiNghiem.Rows[e.Row][flexThiNghiem.Cols.Count - 1].ToString();
                    }
                );

                if (result != null)
                {
                    GiaiDoanVO.LstGiaiDoanDetail.Remove(result);
                }
                else
                {
                    GiaiDoandetail1VO = new GiaiDoanDetailVO();
                    if (GiaiDoanVO != null) { GiaiDoandetail1VO.KeySLGiaiDoan = GiaiDoanVO.KeySL; }
                    GiaiDoandetail1VO.KeySLVatLieu = cboVatlieu.SelectedValue.ToString();
                    GiaiDoandetail1VO.KeySLMauVatLieu = flexThiNghiem.Cols[e.Col].Name;
                    GiaiDoandetail1VO.KeySLThiNghiem = flexThiNghiem.Rows[e.Row][flexThiNghiem.Cols.Count - 1].ToString();
                    GiaiDoanVO.LstGiaiDoanDetail.Add(GiaiDoandetail1VO);
                }

            }
            
        }

       

        private void frmGiaiDoan_KeyDown(object sender, KeyEventArgs e)
        {
            SendKey(this, e);
        }
        public void SendKey(Form frm, KeyEventArgs e)
        {

            try
            {

                if (((((e.KeyCode == Keys.Return) & !e.Alt) & !e.Control) & !e.Shift) && !((frm.ActiveControl.Parent is C1.Win.C1FlexGrid.C1FlexGrid) | (frm.ActiveControl is C1.Win.C1FlexGrid.C1FlexGrid)))
                {

                    if (frm.GetNextControl(frm.ActiveControl, true) != null)
                    {
                        SendKeys.Send("{TAB}");
                    }
                    else
                    {
                        while (frm.GetNextControl(frm.ActiveControl, true) == null)
                        {

                            if (!frm.GetNextControl(frm.ActiveControl, true).Enabled)
                            {
                                frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                            }
                            else
                            {
                                if (!frm.GetNextControl(frm.ActiveControl, true).Visible)
                                {
                                    if (frm.GetNextControl(frm.ActiveControl, true) is TabPage)
                                    {
                                        frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                        return;
                                    }
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is GroupBox)
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is TabControl)
                                {
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is TabPage)
                                {
                                    frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    continue;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is RadioButton)
                                {
                                    if (frm.ActiveControl is RadioButton)
                                    {
                                        SendKeys.Send("{TAB}");
                                    }
                                    else
                                    {
                                        frm.ActiveControl = frm.GetNextControl(frm.ActiveControl, true);
                                    }
                                    return;
                                }
                                if (frm.GetNextControl(frm.ActiveControl, true) is Label)
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                }
                                else
                                {
                                    frm.GetNextControl(frm.ActiveControl, true).Focus();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception exception1)
            {

                Exception exception = exception1;
                throw exception;

            }
        }

        private void flexMauDat_AfterEdit(object sender, RowColEventArgs e)
        {
            if (flexMauDat.Selection.TopRow == 2)
            {
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMNGUYENDANG"] =
                  Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTNGUYENDANG"]) +
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBNGUYENDANG"]);
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMROI"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTROI"]) +
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBROI"]);
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMVATLIEU"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTVATLIEU"]) +
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBVATLIEU"]);
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMDOAM"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTDOAM"]) +
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBDOAM"]);
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMDAMCHAT"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MTDAMCHAT"]) +
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MBDAMCHAT"]);


                flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBNGUYENDANG"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMNGUYENDANG"]) -
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBNGUYENDANG"]);
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBROI"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMROI"]) -
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBROI"]);
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBVATLIEU"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMVATLIEU"]) -
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBVATLIEU"]);
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBDOAM"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMDOAM"]) -
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBDOAM"]);
                flexMauDat.Rows[flexMauDat.Selection.TopRow]["MXBDAMCHAT"] =
                   Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["TMDAMCHAT"]) -
                    Convert.ToInt32(flexMauDat.Rows[flexMauDat.Selection.TopRow]["MKXBDAMCHAT"]);

                SetTong();
            }
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            TVDL4.frmReport f = new frmReport();
            ReportDocument cr = new ReportDocument();
            cr.Load("D:\\Nghia\\SANGKIEN\\TVDL4\\ThreeLayerDemo\\Report\\crpGiaiDoan.rpt");
            List<GiaiDoanVO> lstGiaiDoan = new List<GiaiDoanVO>();
            lstGiaiDoan.Add(GiaiDoanVO);
            //cr.Database.Tables[0].SetDataSource(
            cr.SetDataSource(lstGiaiDoan);
            f.crpView.ReportSource = cr;
            f.Show();
           
        }

       

       

       

       

       

       

        
        
    }
}
